package news;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import models.Listvid;

import utility.DbConnect;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import example.demo_navi.R;

public class TestDb extends Activity{

	private ListView lv;
	ArrayList<HashMap<String, String>> rssFeedList;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.tetdb);
		lv=(ListView) findViewById(R.id.lv02);
		rssFeedList=new ArrayList<HashMap<String,String>>();
		new getDb().execute();
		
	}

	private class getDb extends AsyncTask<String, String, String>{
		DbConnect rssDb = new DbConnect(
				getApplicationContext());
		@Override
		protected String doInBackground(String... params) {
			// TODO Auto-generated method stub
			runOnUiThread(new Runnable() {
				
				public void run() {
					// TODO Auto-generated method stub
				
					rssDb.opend();
					ArrayList<Listvid> siteList = rssDb.getAllPlaylist(10,0);
					
					for (int i = 0; i < siteList.size(); i++) {
						
						Listvid s = siteList.get(i);
						
						HashMap<String, String> map = new HashMap<String, String>();

						map.put("title", s.getLiti().toString());
						map.put("des", s.getLid());
						map.put("pubdate", s.getLithum());

						rssFeedList.add(map);						
				
					}
		
					ListAdapter adapter = new SimpleAdapter(
							TestDb.this,
							rssFeedList, R.layout.site_list_row,
							new String[] { "title", "des", "pubdate" },
							new int[] { R.id.sqlite_id, R.id.title, R.id.link });
	
					lv.setAdapter(adapter);
					registerForContextMenu(lv);
				}
			});
			return null;
		}
		
	}
}
